package com.openapi.protocol.encode;

import com.openapi.data.JT808PushData;
import exsun.jt808.data.base.JT808Category;
import exsun.jt808.data.distribute_data.DistributeEntity;
import exsun.jt808.data.distribute_data.jt1078.*;
import exsun.jt808.data.distribute_data.jt808.*;
import exsun.jt808.data.upload_data.jt808.LatLng;
import exsun.jt808.data.util.parse.BCD8421Operater;
import exsun.jt808.data.util.parse.BitOperator;
import exsun.jt808.data.util.parse.HexStrUtil;

public class Package1078 {
    //文件上传控制
    public static  JT808PushData fileUploadCmdEncode(FileUploadCmd data) {
        byte[] msgBodyBytes = BitOperator.concatAll(
                BitOperator.integerTo2Bytes(data.getPlatSerialNo()),
                BitOperator.integerTo1Bytes(data.getCmd())
        );
        return  new JT808PushData(0x9207,msgBodyBytes, data);
    }
    //文件上传指令
    public static JT808PushData fileUploadReqEncode(FileUploadReq data) {
        byte[] msgBodyBytes = BitOperator.concatAll(
                BitOperator.integerTo1Bytes(data.getIp().length()),
                BitOperator.stringToBytes(data.getIp()),
                BitOperator.integerTo2Bytes(data.getPort()),
                BitOperator.integerTo1Bytes(data.getFtpUserName().length()),
                BitOperator.stringToBytes(data.getFtpUserName()),
                BitOperator.integerTo1Bytes(data.getFtpPassWord().length()),
                BitOperator.stringToBytes(data.getFtpPassWord()),
                BitOperator.integerTo1Bytes(data.getPath().length()),
                BitOperator.stringToBytes(data.getPath()),
                BitOperator.integerTo1Bytes(data.getChanelId()),
                BCD8421Operater.DateToBCD6(data.getBeginTime()),
                BCD8421Operater.DateToBCD6(data.getEndTime()),
                BitOperator.integerTo4Bytes(data.getMediaAlarmFlag()),
                BitOperator.integerTo4Bytes(data.getGpsAlarmFlag()),
                BitOperator.integerTo1Bytes(data.getMediaType()),
                BitOperator.integerTo1Bytes(data.getCodeType()),
                BitOperator.integerTo1Bytes(data.getStorageType()),
                BitOperator.integerTo1Bytes(data.getTaskCondition())
        );
        return  new JT808PushData(0x9206,msgBodyBytes, data);
    }
    //远程录像回放控制
    public static JT808PushData hisMediaUploadCmdEncode(HisMediaUploadCmd data) {
        byte[] msgBodyBytes = BitOperator.concatAll(
                BitOperator.integerTo1Bytes(data.getChanelId()),
                BitOperator.integerTo1Bytes(data.getPlayControl()),
                BitOperator.integerTo1Bytes(data.getPlaySpeed()),
                BCD8421Operater.DateToBCD6(data.getPlayStartTime())
        );
        return  new JT808PushData(0x9202,msgBodyBytes, data);
    }
    //远程录像回放请求
    public static JT808PushData hisMediaUploadReqEncode(HisMediaUploadReq data) {
        byte[] msgBodyBytes = BitOperator.concatAll(
                BitOperator.integerTo1Bytes(data.getIp().length()),
                BitOperator.stringToBytes(data.getIp()),
                BitOperator.integerTo2Bytes(data.getTcpPort()),
                BitOperator.integerTo2Bytes(data.getUdpPort()),
                BitOperator.integerTo1Bytes(data.getChanelId()),
                BitOperator.integerTo1Bytes(data.getMediaType()),
                BitOperator.integerTo1Bytes(data.getCodeType()),
                BitOperator.integerTo1Bytes(data.getStorageType()),
                BitOperator.integerTo1Bytes(data.getPlayType()),
                BitOperator.integerTo1Bytes(data.getPlaySpeed()),
                BCD8421Operater.DateToBCD6(data.getBeginTime()),
                BCD8421Operater.DateToBCD6(data.getEndTime())
        );
        return  new JT808PushData(0x9201,msgBodyBytes, data);
    }
    //查询资源列表
    public static JT808PushData queryMediaListEncode(QueryMediaList data) {
        byte[] msgBodyBytes = BitOperator.concatAll(
                BitOperator.integerTo1Bytes(data.getChanelId()),
                BCD8421Operater.DateToBCD6(data.getBeginTime()),
                BCD8421Operater.DateToBCD6(data.getEndTime()),
                BitOperator.integerTo4Bytes(data.getMediaAlarmFlag()),
                BitOperator.integerTo4Bytes(data.getGpsAlarmFlag()),
                BitOperator.integerTo1Bytes(data.getMediaType()),
                BitOperator.integerTo1Bytes(data.getCodeType()),
                BitOperator.integerTo1Bytes(data.getStorageType())
        );
        return  new JT808PushData(0x9205,msgBodyBytes, data);
    }
    //查询终端音视频属性
    public static JT808PushData queryMediaPropertyEncode(DistributeEntity data) {
        byte[] msgBodyBytes = new byte[0];
        return  new JT808PushData(0x9003,msgBodyBytes, data);
    }
    //实时音视频传输控制
    public static JT808PushData realtimeMediaUploadCmdEncode(RealtimeMediaUploadCmd data) {
        byte[] msgBodyBytes = BitOperator.concatAll(
                BitOperator.integerTo1Bytes(data.getChanelId()),
                BitOperator.integerTo1Bytes(data.getCmdType()),
                BitOperator.integerTo1Bytes(data.getCloseMediaType()),
                BitOperator.integerTo1Bytes(data.getChangeCodeType())
        );
        return  new JT808PushData(0x9102,msgBodyBytes, data);
    }
    //实时音视频传输请求
    public static JT808PushData realtimeMediaUploadReqEncode(RealtimeMediaUploadReq data) {
        byte[] msgBodyBytes = BitOperator.concatAll(
                BitOperator.integerTo1Bytes(data.getIp().length()),
                BitOperator.stringToBytes(data.getIp()),
                BitOperator.integerTo2Bytes(data.getTcpPort()),
                BitOperator.integerTo2Bytes(data.getUdpPort()),
                BitOperator.integerTo1Bytes(data.getChanelId()),
                BitOperator.integerTo1Bytes(data.getMediaType()),
                BitOperator.integerTo1Bytes(data.getCodeType())
        );
        return  new JT808PushData(0x9101,msgBodyBytes,data);
    }

}
